import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)


const store = new Vuex.Store({
  state: {
    userInfo:JSON.parse(localStorage.getItem('userInfo')),
    bread:JSON.parse(sessionStorage.getItem('bread'))?JSON.parse(sessionStorage.getItem('bread')):[],
	setLanguage:'',
	classify:JSON.parse(localStorage.getItem('classify')),
  },
  mutations: {
    ADD_USER(state, val) {
      state.userInfo = val;
	  localStorage.setItem('userInfo', JSON.stringify(val))
      
    },
    ADD_BREAD(state,val){
     state.bread = val;
     sessionStorage.setItem('bread', JSON.stringify(val))

    },
	
	DELALL_BREAD(state,val){
		 state.bread = [];
		 sessionStorage.setItem('bread', JSON.stringify([]))
	},
	
	
	DEL_BREAD(state,index){
		let arr= state.bread.filter(item=>item.path!==index);
		 state.bread = arr;
		 sessionStorage.setItem('bread', JSON.stringify(arr))
	},
	
	ADD_CLASSIFY(state, val) {
      state.classify = val;
	  localStorage.setItem('classify', JSON.stringify(val))
    },
  },
 getters : {
  language: state => state.setLanguage
}
})




export default store;
